# 发布二手物品页面
import time

from base_config import HOST
from pages.base_page import BasePage
from pages.elements import Elements

from utils.log_manager import my_logger


class ReleasePage(BasePage):
    url = HOST + "release"
    pass


    def input_product_info(self,product_info ):
        my_logger.logger.debug("准备发布物品信息:{}",product_info)
        self.input_data(Elements.PRODUCT_NAME_INPUT,product_info['name'])
        self.input_data(Elements.PRODUCT_DETAIL_INPUT, product_info['detail'])
        # todo ,Xpath id 是动态生成的，不好定位
        # option_xpath = f"//li[contains(text(), '{option_text}')]"
        self.click_element(Elements.AREA_INPUT_SELECT)
        time.sleep(2)
        province_eles = self.find_elements(Elements.PROVINCE_CSS_SELECT)
        for e in province_eles:
            text = e.get_attribute("innerText").strip()
            print("text:", text)

        print("============")


        # 选择第一个省份
        province_eles[0].click()
        time.sleep(2)
        city_eles = self.find_elements(Elements.PROVINCE_CSS_SELECT)
        for e in city_eles:
            print(e.text)
        print("============")
        # 选择第一个城市
        city_eles[-1].click()
        time.sleep(1)
        area_eles = self.find_elements(Elements.PROVINCE_CSS_SELECT)

        for e in area_eles:
            print(e.text)
        print("============")

        # 选择第一个区
        area_eles[-1].click()


        # self.click_element(Elements.PROVINCE_SELECT)
        # self.click_element(Elements.CITY_SELECT)
        # self.click_element(Elements.AREA_SELECT)
        #
        self.click_element(Elements.PRODUCT_TYPE_SELECT)
        self.click_element(Elements.PRODUCT_TYPE_1)

        self.input_data(Elements.PRICE_INPUT,product_info['price'])
        self.click_element(Elements.COMFIRM_BUTON)

        self.sleep(3)


